from datetime import date
from typing import Annotated, Optional

from sqlalchemy import func,String,VARCHAR
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column

# 定义常用字段类型别名

optional_int = Annotated[int, mapped_column(nullable=True)]
optional_float = Annotated[float, mapped_column(nullable=True)]
required_str10_pk = Annotated[str, mapped_column(VARCHAR(10), nullable=False, primary_key=True)]
required_date_pk = Annotated[date, mapped_column(nullable=False, primary_key=True)]

class Base(DeclarativeBase):
    pass

class StockData(Base):
    __tablename__ = 'stock_data'

    stock_code: Mapped[required_str10_pk]  # 主键之一
    date:       Mapped[required_date_pk]   # 主键之二

    open:       Mapped[optional_float]
    close:      Mapped[optional_float]
    high:       Mapped[optional_float]
    low:        Mapped[optional_float]

    volume:     Mapped[optional_int]

    turnover_amount:    Mapped[optional_float]
    amplitude:          Mapped[optional_float]
    change_percent:     Mapped[optional_float]
    change_amount:      Mapped[optional_float]
    turnover_rate:      Mapped[optional_float]